/*
 * Copyright 2020-2023 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sagacity.controller;


import com.sagacity.api.OmsOrderRemoteService;
import com.sagacity.entity.OmsOrder;
import com.sagacity.framework.api.model.request.GenericQueryBO;
import com.sagacity.framework.api.model.response.PageResult;
import com.sagacity.framework.api.model.response.ResponseEntity;
import com.sagacity.framework.util.RpcClient;
import com.sagacity.framework.util.SearchUtil;
import com.sagacity.framework.web.controller.BaseController;
import com.sagacity.service.OmsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.undertow.util.QueryParameterUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author yangchangkui
 * @date 2023-05-21 14:06
 */
@Api(tags = "订单相关接口Test")
@RestController
@RequestMapping("/omsOrderTest")
public class OmsOrderTestController {


    @Autowired
    protected OmsOrderRemoteService omsOrderRemoteService;

    @ApiOperation("根据主键ID查询接口")
    @GetMapping("getById")
    public ResponseEntity<OmsOrder> getById(@Valid @NotNull(message = "主键ID不能为空") @RequestParam("id") Serializable id) {
        return ResponseEntity.ok(RpcClient.call(omsOrderRemoteService::getById,id));
    }


    @ApiOperation("get")
    @PostMapping("get")
    public ResponseEntity<OmsOrder> get(@RequestBody OmsOrder entity) {
        return ResponseEntity.ok(RpcClient.call(omsOrderRemoteService::get,entity));
    }


    @ApiOperation("search")
    @PostMapping("search")
    public ResponseEntity<PageResult<OmsOrder>> search(@RequestBody GenericQueryBO<OmsOrder> bo) {

        GenericQueryBO<OmsOrder> queryBO = SearchUtil.<OmsOrder>builder()
                .in("id", 14,15)
                .gt("createTime", "2018-09-13 14:03:00.00")
//                .page(1,10)
                .includes("id","member_id","createTime>test")
                .build();
        PageResult call = RpcClient.call(omsOrderRemoteService::search, queryBO, t -> {
            PageResult pageResult = new PageResult();
            pageResult.setTotal(100);
            return pageResult;
        });



        return ResponseEntity.ok(RpcClient.call(omsOrderRemoteService::search,queryBO,"服务太火爆，请稍后再试"));
    }

}

